/*
* Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
* Description: image_sender_base head file
*/
#ifndef IMAGE_SENDER_BASE_H
#define IMAGE_SENDER_BASE_H
#include <sys/time.h>
#include <unistd.h>
#include <string>
#include <memory>
#include <cstdlib>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <vector>
#include "mdc/cam/camera/cameradecodedserviceinterface_skeleton.h"
#include "mdc/cam/camera/cameradecodedmbufserviceinterface_skeleton.h"

static struct CommandPara {
    std::string fileType{""};
    std::string configFile{""};
    std::string transMode{""};
    std::string frequency{""};
    bool loop{false};
    std::string time{""};
} comPara;

using CameraHeaderMbufStruct = ara::camera::CameraHeaderMbufStruct;
struct YuvImageInfo {
    CameraHeaderMbufStruct header;
    uint32_t width = 0U;
    uint32_t height = 0U;
    uint32_t sendTimeHigh = 0U;
    uint32_t sendTimeLow = 0U;
    uintptr_t mbuffer = 0U;
    uint32_t length = 0U;
};

template <class ProxyType>
class ImageSenderBase
{
public:
    ImageSenderBase() = default;
    virtual ~ImageSenderBase() = default;
    ImageSenderBase(uint32_t id, cv::Size s, std::string dir) : instanceId(id), imgSize(s), dir(dir)
    {
        frameID += std::to_string(id);
    }
    bool RegisterSender()
    {
        using ara::com::InstanceIdentifier;
        using ara::com::MethodCallProcessingMode;
        std::string idStr = std::to_string(instanceId);
        std::cout << "Begin to Register to publish instance id: " << idStr << std::endl;
        ara::core::StringView id(idStr.c_str());
        dataSkeleton = std::make_unique<ProxyType>(InstanceIdentifier(id), MethodCallProcessingMode::kPoll);
        if (dataSkeleton == nullptr) {
            std::cerr << "Publish to instance id: " << idStr << "failed!" << std::endl;
            return false;
        }
        dataSkeleton->OfferService();
        std::cerr << "Publish to instance id: " << idStr << " succeed!" << std::endl;
        return true;
    }
    virtual void FillImageAndSend(std::string imgPath, uint32_t seq, void *flag) = 0;

protected:
    uint32_t instanceId{ 21 };
    std::string frameID{"sender_"};
    std::shared_ptr<ProxyType> dataSkeleton{};
    std::string dir{""};
public:
    cv::Size imgSize{1920, 1080};
};

#endif // IMAGE_SENDER_BASE_H
